#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
// 创建两个没有关系的进程，使用有名管道进行各进程间通讯
#define FIFO_NAME "./myfifo"
int main(int argc, char const *argv[])
{
    // 创建有名管道
    int ret = mkfifo(FIFO_NAME, 0644);
    if (ret == -1) {
        perror("mkfifo fail \n");
        exit(EXIT_FAILURE);
    }

    /* code */
    int fd = open(FIFO_NAME, O_RDONLY);
    if (fd == -1) {
        perror("open fail \n");
        exit(EXIT_FAILURE);
    }
    // 读取文件
    char buf[64];
    int rbytes = read(fd,  buf, sizeof(buf));
    if (rbytes == -1) {
        perror("read fail \n");
        exit(EXIT_FAILURE);
    }
    printf("buf = %s \n", buf);
    close(fd);

    return 0;
}
